<?php

namespace app\model;

use think\Model;

class UserDepartmentRelationModel extends Model
{
    protected $name = 'user_department_relation';


    /**
     * Notes: 获取部门下的所有 员工
     * User: chenLei
     * Date: 9/7/25
     * @param $params
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getDepartmentUserList($params)
    {
        $user_ids = $this->where('department_id', $params['department_id'])->column('user_id');

        $user = UserModel::where('id', 'in', $user_ids)->field('id,username,realname')->select()->toArray();

        return $user;
    }


    /**
     * Notes: 获取部门权限
     * User: chenLei
     * Date: 9/15/25
     * @param $params
     * @return array
     */
    public function approvalAuthority($user_id)
    {

        $department_id_array = $this->where('user_id', $user_id)->column('department_id');


        $departmentModel = new UserDepartmentModel();

        $code_array = $departmentModel->where("id", 'in', $department_id_array)->column('code');

        return $code_array;
    }
}